public class Test02 {
    public int[] searchRange(int[] nums, int target) {
        if(nums.length == 0) return new int[]{-1 ,-1};
        int[] ret = new int[2];
        int left = findLeft(nums,target);
        int right = findRight(nums,target);
        ret[0] = left; ret[1] = right;
        return ret;

    }

    private static int findLeft(int[] nums , int target){
        int left = 0 , right = nums.length - 1;
        int mid = 0;
        while(left < right){
            mid = left + (right - left) / 2;
            if(nums[mid] < target) left = mid + 1;
            else right = mid;
        }
        if(nums[left] != target) return  -1;
        else return left;
    }

    private static int findRight(int[] nums , int target){
        int left = 0 , right = nums.length - 1;
        int mid = 0;
        while(left < right){
            mid = left + (right - left + 1) / 2;
            if(nums[mid] <= target) left = mid ;
            else right = mid -1;
        }
        if(nums[left] != target) return  -1;
        else return right;
    }
}
